# 斐波那契数列
class ParamsTypeError(Exception):
    def __init__(self, n):
        self.num = n


while True:
    try:
        n1 = 0
        n2 = 1
        count = 2
        num = input("输入需要几项（正整数）：")
        if not num.isdigit():
            raise ParamsTypeError(num)

        n3 = int(num)
        if n3 <= 0:
            print("请输入一个正整数！")
            continue
        elif n3 == 1:
            print("斐波那契数列：")
            print(n1)
        else:
            print("斐波那契数列：")
            print(n1, n2, end=" ")
            for i in range(2, n3+1):
                tmp = n1 + n2
                print(tmp, end=" ")
                n1 = n2
                n2 = tmp
        break
    except ParamsTypeError as p:
        print("ParamsTypeError:请输入正整数！你输入的是：", p.num)
